package org.yawnage.logic 
{
	import flash.events.MouseEvent;
	import org.yawnage.framework.server.Publisher;
	import org.yawnage.framework.server.RegisterView;
	import org.yawnage.interfaces.framework.IPublisher;
	import org.yawnage.interfaces.framework.ISubscriber;
	import org.yawnage.interfaces.framework.ITransportLayer;
	import org.yawnage.views.AwayView;
	import org.yawnage.views.HomeView;
	import spark.components.Button;
	import spark.components.View;
	/**
	 * ...
	 * @author ...
	 */
	public class TestPublisher2  extends Publisher implements ISubscriber,IPublisher
	{
		
		private var _view:AwayView;
		
		public function TestPublisher2() 
		{
			super("test2");
			setClassDescription("org.yawnage.logic.TestPublisher2");
		}
		
		override public function defineServices():void {
			registerService(this, "lazyService");
			registerService(this, "doggie");
			
			subscribe(this, onViewReady, "AwayView", RegisterView.VIEW_READY);
			subscribe(this, onExpire, "AwayView", RegisterView.VIEW_EXPIRE);
		
		}
		
		private function onExpire(t:ITransportLayer = null):void 
		{
			_view = null;
		}
		
		private function onViewReady(t:ITransportLayer):void 
		{
			_view = AwayView(t.data);
			Button(_view.backButton).addEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function onClick(e:MouseEvent):void 
		{
			View(_view).navigator.pushView(HomeView);
		}
		
	}

}